function fsb_noise_map(sandbox,hrf_pred)

% FSB : Plot noise timecourse maps
%
% EXAMPLE:
% fsb_noise_map(sandbox,1)
%
% INPUT:
% sandbox :         experiment information struct
%                   containing noise maps
% hrf_pred:         hemodynamic predictor used
%
% OUTPUT:
% Noise maps
%
% CALLED BY:
% fsb_diag.m
%
% Copyright 2010 MPI for Biological Cybernetics
% Author: Steffen Stoewer
% License:GNU GPL, no express or implied warranties
% 
%$ Revision 1.0
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Plot absolute deviation for slices along both sides of the brain
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
figure(121);
set(gcf,'Name','Absolute deviation from mean over time');
clf;

subplot(3,1,1);
mean_art = mean(sandbox.art_mean_x);
art_mean = sandbox.art_mean_x-mean_art;
scalfac1 = (max(art_mean)-min(art_mean))/(max(sandbox.hemodynamics(:,hrf_pred))-min(sandbox.hemodynamics(:,hrf_pred)));
scalfac2 = mean(art_mean(:));
plot (art_mean);title ('Mean value of slices along both sides of the brain', 'Color', 'k', 'FontSize',12);
hold on;
plot(sandbox.hemodynamics(:,hrf_pred)*scalfac1+scalfac2,'r');
noisecorr = corr(art_mean,sandbox.hemodynamics(:,hrf_pred));
text(1,max(art_mean),['Noise correlation : ' num2str(noisecorr)]);
legend('Noise TC','HRF predictor');

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Plot absolute deviation from mean for slice behind the brain
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

subplot(3,1,2);
mean_art = mean(sandbox.art_mean_y);
art_mean = sandbox.art_mean_y -mean_art;
scalfac1 = (max(art_mean)-min(art_mean))/(max(sandbox.hemodynamics(:,hrf_pred))-min(sandbox.hemodynamics(:,hrf_pred)));
scalfac2 = mean(art_mean(:));
plot (art_mean);title ('Mean value of slice behind the back of the brain', 'Color', 'k', 'FontSize',12);
hold on;
plot(sandbox.hemodynamics(:,hrf_pred)*scalfac1+scalfac2,'r');
noisecorr = corr(art_mean,sandbox.hemodynamics(:,hrf_pred));
text(1,max(art_mean),['Noise correlation : ' num2str(noisecorr)]);
legend('Noise TC','HRF predictor');

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Plot absolute deviation from mean for slice through middle of brain
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

subplot(3,1,3);
mean_art = mean(sandbox.art_mean_brain);
art_mean = sandbox.art_mean_brain-mean_art;
scalfac1 = (max(art_mean)-min(art_mean))/(max(sandbox.hemodynamics(:,hrf_pred))-min(sandbox.hemodynamics(:,hrf_pred)));
scalfac2 = mean(art_mean(:));
plot (art_mean);title ('Mean value of sagittal slice through middle of brain', 'Color', 'k', 'FontSize',12);
hold on;
plot(sandbox.hemodynamics(:,hrf_pred)*scalfac1+scalfac2,'r');
noisecorr = corr(art_mean,sandbox.hemodynamics(:,hrf_pred));
text(1,max(art_mean),['Noise correlation : ' num2str(noisecorr)]);
legend('Noise TC','HRF predictor');

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Plot % deviation from mean for slices along both sides of the brain
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
figure(122);set(gcf,'Name','Percent deviation from mean over time');
clf;

subplot(3,1,1);
mean_art = mean(sandbox.art_mean_x);
art_mean = sandbox.art_mean_x/mean_art;
scalfac1 = (max(art_mean)-min(art_mean))/(max(sandbox.hemodynamics(:,hrf_pred))-min(sandbox.hemodynamics(:,hrf_pred)));
scalfac2 = mean(art_mean(:));
plot (art_mean);title ('Mean value of slices along both sides of the brain', 'Color', 'k', 'FontSize',12);
hold on;
plot(sandbox.hemodynamics(:,hrf_pred)*scalfac1+scalfac2,'r');
noisecorr = corr(art_mean,sandbox.hemodynamics(:,hrf_pred));
text(1,max(art_mean),['Noise correlation : ' num2str(noisecorr)]);
legend('Noise TC','HRF predictor');

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Plot % deviation from mean  for slice behind the brain
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

subplot(3,1,2);
mean_art = mean(sandbox.art_mean_y);

art_mean = sandbox.art_mean_y /mean_art;
scalfac1 = (max(art_mean)-min(art_mean))/(max(sandbox.hemodynamics(:,hrf_pred))-min(sandbox.hemodynamics(:,hrf_pred)));
scalfac2 = mean(art_mean(:));
plot (art_mean);title ('Mean value of slice behind the back of the brain', 'Color', 'k', 'FontSize',12);
hold on;
plot(sandbox.hemodynamics(:,hrf_pred)*scalfac1+scalfac2,'r');
noisecorr = corr(art_mean,sandbox.hemodynamics(:,hrf_pred));
text(1,max(art_mean),['Noise correlation : ' num2str(noisecorr)]);
legend('Noise TC','HRF predictor');

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Plot % deviation from mean  for slice through middle of brain
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
subplot(3,1,3);
mean_art = mean(sandbox.art_mean_brain);
art_mean = sandbox.art_mean_brain/mean_art;
scalfac1 = (max(art_mean)-min(art_mean))/(max(sandbox.hemodynamics(:,hrf_pred))-min(sandbox.hemodynamics(:,hrf_pred)));
scalfac2 = mean(art_mean(:));
plot (art_mean);title ('Mean value of sagittal slice through middle of brain', 'Color', 'k', 'FontSize',12);
hold on;
plot(sandbox.hemodynamics(:,hrf_pred)*scalfac1+scalfac2,'r');
noisecorr = corr(art_mean,sandbox.hemodynamics(:,hrf_pred));
text(1,max(art_mean),['Noise correlation : ' num2str(noisecorr)]);
legend('Noise TC','HRF predictor');

end
